﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using roysland.net.xcom.core.DataAccess;
using roysland.net.xcom.core.Models;

namespace roysland.net.xcom.core.Helpers
{
    public static class GeoscapeExeParser
    {
        private static byte[] buffer;
        private const int RecordCraftsLength = 28;
        private const int OffsetCraftStats = 353020;

        private static void GetData()
        {
            buffer = XComDataAccess.GetGeoscapeExeData();
        }

        public static List<CraftStat> GetCraftStats()
        {
            if (buffer == null)
                GetData();

            var counter = 1;
            var records = new List<CraftStat>();
            for (int i = 0; i < 14; i++)
            {
                var offset = (i * RecordCraftsLength) + OffsetCraftStats;
                var buff = ByteHelper.GetByteSegment(offset, RecordCraftsLength, buffer);
                records.Add(new CraftStat(buff, counter));
                counter++;
            }

            return records;
        }

    }
}
